﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OCR
{
    public partial class Picture : Form
    {
        //边界值
        private int value;
        public Picture()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.openFileDialog1.Filter = "图像|*.bmp;*.jpg;*.png|所有文件|*.*"; 
            if(this.openFileDialog1.ShowDialog()==System.Windows.Forms.DialogResult.OK)
            {
                this.textBox1.Text = this.openFileDialog1.FileName;
                this.pictureBox1.Image = Image.FromFile(this.textBox1.Text);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Bitmap bitmap = new Bitmap(this.pictureBox1.Image);
            this.pictureBox2.Image = ImageUtils.ToGrayBitmap(bitmap); 
        }

        private void button3_Click(object sender, EventArgs e)
        {
           
            Bitmap bitmap = new Bitmap(this.pictureBox1.Image);
            this.pictureBox3.Image = ImageUtils.ToBinaryBitmap(bitmap, BinarizationMethods.Otsu, out value); 
        }
     
        private void button4_Click(object sender, EventArgs e)
        {
            Bitmap bitmap = new Bitmap(this.pictureBox1.Image);
            this.pictureBox4.Image = ImageUtils.ToBinaryBitmap(bitmap, BinarizationMethods.Iterative, out value);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Bitmap bitmap = new Bitmap(this.pictureBox3.Image);
            bitmap.Save(@"c:\123.jpg",ImageFormat.Jpeg);

        }
        //杂点
        private void button6_Click(object sender, EventArgs e)
        {
            Bitmap bitmap = new Bitmap(this.pictureBox3.Image);
            ImageUtils.ClearNoise(this.value, 3, bitmap);
            this.pictureBox4.Image = bitmap;
        }
        //中波
        private void button7_Click(object sender, EventArgs e)
        {
            

            Bitmap bitmap = new Bitmap(this.pictureBox3.Image);
            ImageUtils.ClearNoise(this.value, bitmap);
            this.pictureBox4.Image = bitmap;

        }
    }
}
